;;
;; @file  le-emacs-global.el
;; @date  2011/10/22
;; @usage just load this file. NOT other plugin to install
;;        for this to function.
;;

;; user infomation
(setq user-full-name "GanXL")
(setq user-mail-address "ganxiangle@gmail.com")

;; don't show toolbar,startup-screen	
(setq inhibit-startup-screen t)
(scroll-bar-mode nil) 
(setq size-indication-mode t)
(tool-bar-mode 0)
		 
;; set first frame pos and size
(setq initial-frame-alist '((top . 0) (left . 0)
                            (width . 82) (height . 42)))
;; set susequent frames pos and sizes
(setq default-frame-alist '((width . 82) (height . 42)))
		 
;; transparency 
(setq alpha-list '((100 100) (95 65) (85 55) (75 45) (65 35)))
(defun loop-alpha ()
  (interactive)
  (let ((h (car alpha-list)))            
    ((lambda (a ab)
       (set-frame-parameter (selected-frame) 'alpha (list a ab))
       (add-to-list 'default-frame-alist (cons 'alpha (list a ab))))
     (car h) (car (cdr h)))
    (setq alpha-list (cdr (append alpha-list (list h))))
    )
  )
		 
;; show time
(display-time-mode 1)
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)

;; show line number the cursor is on, in status bar 
(line-number-mode 1)
;; display line numbers in margin (fringe). 
(global-linum-mode 1) 

;; let cursor's line position and column position 
;; show in the status bar, like this: (166,3).
(column-number-mode 1)
;(setq column-number-mode t)

;; hide password echo in shell mode
(add-hook 'comint-output-filter-functions
	  'comint-watch-for-password-prompt)

;; turn on parent match highlighting
(show-paren-mode 1)

;; turn on highlighting current line
;(global-hl-line-mode 1)
	  
;; replace 'yes'/'no' to 'y'/'n'
(fset 'yes-or-no-p 'y-or-n-p)

;; solve artist-mode mouse problem
(defadvice artist-coord-win-to-buf
  (before fixup-artist-position activate compile)
  (if tabbar-mode (setq coord (cons (car coord) (1- (cdr coord))))))

;; auto formating the copy code 
(dolist (command '(yank yank-pop))
  (eval
   `(defadvice ,command (after indent-region activate)
      (and (not current-prefix-arg)
	   (member major-mode
		   '(emacs-lisp-mode
		     lisp-mode
		     clojure-mode
		     scheme-mode
		     haskell-mode
		     ruby-mode
		     rspec-mode
		     python-mode
		     c-mode
		     c++-mode
		     objc-mode
		     latex-mode
		     js-mode
		     plain-tex-mode))
	   (let ((mark-even-if-inactive transient-mark-mode))
	     (indent-region (region-beginning) (region-end) nil))))))

;; wrap the compile fun
(setq compile-command "make")
(defun du-onekey-compile ()
  "Save buffers and start compile"
  (interactive)
  (save-some-buffers t)
  (setq compilation-read-command nil)
  (compile compile-command)
  (setq compilation-read-command t)
  )
  
;; Permanently force Emacs to indent with spaces, never with TABs:
;;   M-x tabify   replacing two or above SPACEs with TAB
;;   M-x untabify replacing TAB with SPACEs
(setq-default indent-tabs-mode nil)

;; make emacs stop creating those "backup~" files or 
;; those "#autosave#" files
(setq make-backup-files nil)
(setq auto-save-default nil)

(setq buffer-offer-save t)
(setq comment-column 40)
(setq next-line-add-newlines t)


;; set c indentation style
;; available optinos: bsd, gnu, linux, k&r, cc-mode(default)
(add-hook 'c-mode-hook
          '(lambda ()
             (c-set-style "stroustrup")))

;; TAB to blank
(setq tab-width 4
      indent-tabs-mode t
      c-basic-offset 4)

;; Turn off annoying beeping and getting a flashing alarm
(setq visible-bell 1)
;; but flashing is also annoying, turn alarm off totally
(setq ring-bell-function 'ignore)


;; Set language environment: Chinese-GB/Chinese-GBK/UTF-8
(set-language-environment 'UTF-8)
;; By default, keyboard input is translated based on your system locale
;; setting.
(set-keyboard-coding-system 'utf-8)
;; If you specify a character code for terminal output, all characters
;; output to the terminal are translated into that coding system. 
(set-terminal-coding-system 'utf-8)
;; The default for coding system that write from this buffer into a file,
;; such as save-buffer and write-region. utf-8 means NO BOM utf-8.
(set-buffer-file-coding-system 'utf-8-dos)
;; The variable file-name-coding-system specifies a coding system to use
;; for encoding file names. It has no effect on reading and writing the
;; contents of files.
(set-file-name-coding-system 'cn-gb-2312)
;; Specifing the coding system for input and output to a subprocess.
;; This command applies to the current buffer; normally, each subprocess
;; has its own buffer, and thus you can use this command to specify
;; translation to and from a particular subprocess by giving the command
;; in the corresponding buffer. 
;(setq buffer-process-coding-system '('cn-gb-2312 'cn-gb-2312))

;; To read and write all '.txt' files using the coding system gb2312
;(modify-coding-system-alist 'file "\\.txt\\'" 'cn-gb-2312-dos)
(modify-coding-system-alist 'file "\\.c\\'" 'cn-gb-2312-dos)
(modify-coding-system-alist 'file "\\.h\\'" 'cn-gb-2312-dos)

(defun reread-file-with-utf-8()
  "if default decoding is gb, the chinse fonts in
   GB2312 will display roght."
  (interactive)
  (revert-buffer-with-coding-system 'utf-8))
(defun reread-file-with-gb2312()
  (interactive)
  (revert-buffer-with-coding-system 'cn-gb-2312-dos))

;; Open shell-mode with encoding gb2312, which works well for Windows native
;; Coding System GB2312.
(defun  windows-cmd()
  "My custom shell command "
  (interactive)
  (shell)
  (set-buffer-process-coding-system 'cn-gb-2312 'cn-gb-2312))

;========================== global key binding==============================
(global-set-key [f1]  'tabbar-backward-tab)
(global-set-key [f2]  'tabbar-forward-tab)
(global-set-key [f3]  'tabbar-backward-group)
(global-set-key [f4]  'tabbar-forward-group)
(global-set-key [f5]  'windows-cmd)
(global-set-key [f6]  'reread-file-with-gb2312)
(global-set-key [f7]  'yas/new-snippet)
(global-set-key [f8]  'yas/insert-snippet)
(global-set-key [f9]  'eshell)
(global-set-key [f10] 'kill-buffer-and-window)
(global-set-key [f11] 'other-window)
(global-set-key [f12] 'delete-other-windows)

(global-set-key [S-f1]   'loop-alpha)
(global-set-key [S-f4]   'du-onekey-compile)
(global-set-key [S-f9]   'shell-command)
(global-set-key [S-f10]  'bookmark-set)
(global-set-key [S-f11]  'bookmark-bmenu-list)

(global-set-key (kbd "C-9") 'find-file-other-window)

(global-set-key (kbd "C-c C-w") 'clipboard-kill-ring-save)
(global-set-key (kbd "C-c C-y") 'clipboard-yank)
(global-set-key (kbd "C-c C-c") 'comment-or-uncomment-region)
(global-set-key (kbd "C-c C-k") 'comment-kill)
(global-set-key (kbd "C-8")     'kill-whole-line)
(global-set-key (kbd "C-c C-m") 'set-mark-command)

;(global-set-key [f7]  'hs-show-all)
;(global-set-key [f8]  'hs-toggle-hiding)
;(global-set-key [f7]  'woman)
;(global-set-key [S-f2]  'create-tags)











